{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total number of records  (14999, 10)\n",
      "Number of outliers  (1500, 22)\n",
      "Number of non outliers  (13499, 22)\n"
     ]
    }
   ],
   "source": [
    "##Isolation forest\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from sklearn.ensemble import IsolationForest\n",
    "hr_data = pd.read_csv('data/hr.csv', header=0)\n",
    "print('Total number of records ',hr_data.shape)\n",
    "hr_data = hr_data.dropna()\n",
    "data_trnsf = pd.get_dummies(hr_data, columns =['salary', 'sales'])\n",
    "data_trnsf.columns\n",
    "clf = IsolationForest(n_estimators=100)\n",
    "clf.fit(data_trnsf)\n",
    "y_pred_train = clf.predict(data_trnsf)\n",
    "data_trnsf['outlier'] = y_pred_train\n",
    "print('Number of outliers ',data_trnsf.loc[data_trnsf['outlier'] == -1].shape)\n",
    "print('Number of non outliers ',data_trnsf.loc[data_trnsf['outlier'] == 1].shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
